var Response = require('nitro/response').Response;
var users = require('google/appengine/api/users');

/**
 * HTTP GET handler for /apis/auth/login
 * Redirects the user's browser to the App Engine-provided login page.  After
 * logging in, the user will be redirected back to their original location
 * within the app.
 *
 * pathInfo:  The current hash location within the app when the user clicks the
 *    login link.
 * Ex:  /apis/auth/login/raider will redirect to /#/raider after login.
 */
exports.GET = function(req) {
  // pathInfo is the location within the app the user was at.
  var loginURL = users.createLoginURL('/apis/referer' + req.pathInfo);
  
  var response = Response.redirect(loginURL);
  return response;
};